home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_lowmemory.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  8.2 KB  |  241 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. static APTR LowMemPool = NULL;
  33.  
  34. __asm __saveds LONG lowmemorylist_dspfunc(register __a2 char **array, register __a1 struct LowMemoryEntry *lowmemoryentry, register __a0 struct Hook *hook)
  35. {
  36.    if (lowmemoryentry) {
  37.       *array++ = lowmemoryentry->lowmemory_address;
  38.       *array++ = lowmemoryentry->lowmemory_name;
  39.       *array++ = lowmemoryentry->lowmemory_type;
  40.       *array++ = lowmemoryentry->lowmemory_pri;
  41.       *array++ = lowmemoryentry->lowmemory_data;
  42.       *array++ = lowmemoryentry->lowmemory_code;
  43.       *array   = NULL;
  44.    } else {
  45.       *array++ = ESC "bAddress";
  46.       *array++ = ESC "bln_Name";
  47.       *array++ = ESC "bln_Type";
  48.       *array++ = ESC "bln_Pri";
  49.       *array++ = ESC "bis_Data";
  50.       *array++ = ESC "bis_Code";
  51.       *array   = NULL;
  52.    }
  53.    return(0);
  54. }
  55.  
  56. struct Hook lowmemorylist_dsphook = {
  57.  {NULL, NULL},
  58.  (ULONG (* )())lowmemorylist_dspfunc,
  59.  NULL, NULL
  60. };
  61.  
  62. void FreeLowMemory (void)
  63. {
  64.     MyFreePoolStructs(&LowMemPool, lowmemorytext, NULL, lowmemorylist);
  65. }
  66.  
  67. int GetLowMemory (struct LowMemoryEntry **first) {
  68.    struct   Interrupt      *intr;
  69.    struct   LowMemoryEntry *lowmemoryentry,*previous = NULL;
  70.    char     code[FILENAMELENGTH + 1];
  71.  
  72.    int lowmemorycnt = 0;
  73.    *first = 0;
  74.  
  75.    if (!LowMemPool) LowMemPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  76.  
  77.    if (clientstate) {
  78.       if (SendDaemon ("GetLowMemList")) {
  79.          while ((lowmemoryentry = tbAllocPooled(LowMemPool, sizeof(struct LowMemoryEntry))) \
  80.            && (ReceiveDecodedEntry ((UBYTE *) lowmemoryentry, sizeof (struct LowMemoryEntry)))) {
  81.             IsHex (lowmemoryentry->lowmemory_address, (long *) &lowmemoryentry->lowmemory_adr);
  82.  
  83.             if (! *first)
  84.                *first = lowmemoryentry;
  85.             if (previous)
  86.                previous->lowmemory_next = lowmemoryentry;
  87.  
  88.             lowmemorycnt++;
  89.             previous = lowmemoryentry;
  90.          }
  91.       }
  92.    } else {
  93.       if (SysBase->LibNode.lib_Version >= 39) {
  94.          if (intr = (struct Interrupt *)SysBase->ex_MemHandlers.mlh_Head) {
  95.             while ((intr->is_Node.ln_Succ != 0) && (lowmemoryentry = tbAllocPooled(LowMemPool, sizeof(struct LowMemoryEntry)))) {
  96.                if (! *first)
  97.                   *first = lowmemoryentry;
  98.                if (previous)
  99.                   previous->lowmemory_next = lowmemoryentry;
  100.  
  101.                lowmemoryentry->lowmemory_adr = intr;
  102.  
  103.                code[0] = '\0';
  104.                if (points2ram((APTR) intr->is_Code)) {
  105.                   _sprintf (code, HELL "$%08lx" DUNKEL, intr->is_Code);
  106.                } else {
  107.                   _sprintf (code, "$%08lx", intr->is_Code);
  108.                }
  109.                _sprintf (lowmemoryentry->lowmemory_address, "$%08lx", intr);
  110.                strncpy (lowmemoryentry->lowmemory_name, nonetest (intr->is_Node.ln_Name), 27);
  111.                strcpy (lowmemoryentry->lowmemory_type, GetNodeType (intr->is_Node.ln_Type));
  112.                _sprintf (lowmemoryentry->lowmemory_pri, "%4ld ", intr->is_Node.ln_Pri);
  113.                _sprintf (lowmemoryentry->lowmemory_data, "$%08lx", intr->is_Data);
  114.                strcpy (lowmemoryentry->lowmemory_code, code);
  115.                lowmemorycnt++;
  116.  
  117.                previous = lowmemoryentry;
  118.                intr = (struct Interrupt *) intr->is_Node.ln_Succ;
  119.             }
  120.          }
  121.       }
  122.    }
  123.    return (lowmemorycnt);
  124. }
  125.  
  126. void PrintLowMemory (char *filename) {
  127.    int   i=1;
  128.    BPTR  handle;
  129.    struct LowMemoryEntry *entryp = NULL;
  130.  
  131.    handle = HandlePrintStart (filename);
  132.    if ((handle) && (PrintOneLine (handle, "\n  Address  Type       Pri    Data       Code     Name\n\n"))) {
  133.       if (! WI_LowMemory) {
  134.          i = GetLowMemory (&entryp);
  135.       }
  136.       if (i) {
  137.          for (i=0;;i++) {
  138.             if (WI_LowMemory)
  139.                DoMethod (lowmemorylist,MUIM_List_GetEntry,i,&entryp);
  140.             if (!entryp) break;
  141.  
  142.             if (points2ram ((APTR) (entryp->lowmemory_adr->is_Code)))
  143.                strcpy (tmpstr, entryp->lowmemory_code+2);
  144.             else
  145.                strcpy (tmpstr, entryp->lowmemory_code);
  146.  
  147.             _sprintf (tmpstr2, " %s %-9s %4s %s %-9.9s %s\n", entryp->lowmemory_address, entryp->lowmemory_type, entryp->lowmemory_pri, entryp->lowmemory_data, tmpstr, entryp->lowmemory_name);
  148.             if (! (PrintOneLine (handle, tmpstr2)))
  149.                break;
  150.  
  151.             if (! WI_LowMemory)
  152.                entryp = entryp->lowmemory_next;
  153.          }
  154.       }
  155.    }
  156.    HandlePrintStop();
  157. }
  158.  
  159. void ShowLowMemory (void) {
  160.    struct LowMemoryEntry *lowmemory;
  161.  
  162.    ApplicationSleep();
  163.    set (lowmemorylist,MUIA_List_Quiet,TRUE);
  164. //*   set (BT_LowMemoryCause, MUIA_Disabled, TRUE);
  165.    set (BT_LowMemoryRemove, MUIA_Disabled, TRUE);
  166.    set (BT_LowMemoryPriority, MUIA_Disabled, TRUE);
  167.  
  168.    FreeLowMemory();
  169.    lowmemorycnt = GetLowMemory (&lowmemory);
  170.  
  171.    while (lowmemory) {
  172.       InsertBottomEntry (lowmemorylist, (APTR *) &lowmemory);
  173.       lowmemory = lowmemory->lowmemory_next;
  174.    }
  175.  
  176.    SetCountText (lowmemorycount, lowmemorycnt);
  177.    AwakeApplication();
  178.    set (lowmemorylist,MUIA_List_Quiet,FALSE);
  179. }
  180.  
  181. void SendLowMemory (void) {
  182.    struct LowMemoryEntry *lowmemory;
  183.  
  184.    FreeLowMemory();
  185.    lowmemorycnt = GetLowMemory (&lowmemory);
  186.  
  187.    while (lowmemory) {
  188.       SendEncodedEntry ((UBYTE *) lowmemory, sizeof (struct LowMemoryEntry));
  189.       lowmemory = lowmemory->lowmemory_next;
  190.    }
  191.    FreeLowMemory();
  192. }
  193.  
  194.  
  195. char lowmemory_title[WINDOWTITLELEN];
  196.  
  197. void LowMemoryWindow (BOOL state) {
  198.    if (state) {
  199.       if (WI_LowMemory) {
  200.          ShowLowMemory();
  201.       } else {
  202.          WI_LowMemory = WindowObject,
  203.          MUIA_Window_Title, MyGetWindowTitle (lowmemory_title, "LOWMEMORY"),
  204.          MUIA_HelpNode, LowMemoryText,
  205.          MUIA_Window_ID, MakeListID('L','O','W','M'),
  206.          WindowContents, VGroup,
  207.             Child, lowmemorylist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8,COL=5",&lowmemorylist_dsphook),
  208.             Child, MyBelowListview (&lowmemorytext, &lowmemorycount),
  209.             Child, MyVSpace(2),
  210.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  211.                Child, BT_LowMemoryUpdate    = KeyButtonA (UpdateText  ,ID_LOWMEMORYUPDATE),
  212.                Child, BT_LowMemoryPrint     = KeyButtonA (PrintText   ,ID_LOWMEMORYPRINT),
  213. //*               Child, BT_LowMemoryCause     = KeyButtonA (CauseText   ,ID_LOWMEMORYCAUSE),
  214.                Child, BT_LowMemoryRemove    = KeyButtonA (RemoveText  ,ID_LOWMEMORYREMOVE),
  215.                Child, BT_LowMemoryPriority  = KeyButtonA (PriorityText,ID_LOWMEMORYPRIORITY),
  216.                Child, BT_LowMemoryExit      = KeyButtonA (ExitText    ,ID_LOWMEMORYEXIT),
  217.             End,
  218.          End, End;
  219.  
  220.          DoMethod (AP_Scout,OM_ADDMEMBER,WI_LowMemory);
  221.          DoMethod (WI_LowMemory,MUIM_Window_SetCycleChain,lowmemorylist,BT_LowMemoryUpdate,BT_LowMemoryPrint,BT_LowMemoryRemove,BT_LowMemoryPriority,BT_LowMemoryExit,NULL);
  222.  
  223.          SetCloseRequest (WI_LowMemory,ID_LOWMEMORYEXIT);
  224.          SetListActive (lowmemorylist,ID_LOWMEMORYLV_ACTIVE);
  225.  
  226.          ShowLowMemory();
  227.  
  228.          SetWindowOpen (WI_LowMemory,lowmemorylist,ID_LOWMEMORYEXIT);
  229.       }
  230.    } else if ((! state) && (WI_LowMemory)) {
  231.       SetWindowClose (WI_LowMemory,TRUE);
  232.  
  233.       FreeLowMemory();
  234.  
  235.       DoMethod (AP_Scout,OM_REMMEMBER,WI_LowMemory);
  236.       MUI_DisposeObject (WI_LowMemory);
  237.       WI_LowMemory = NULL;
  238.       lowmemorylist = NULL;
  239.    }
  240. }
  241.